package leecode

import "sort"

func findKthSmallest(coins []int, k int) int64 {
	// 使用集合去重
	amountsSet := make(map[int]struct{})

	// 对每个面额的硬币，计算可制造的金额
	for _, coin := range coins {
		for amount := coin; amount <= coin*k; amount += coin {
			amountsSet[amount] = struct{}{}
		}
	}

	// 将集合转换为列表
	amountsList := make([]int, 0, len(amountsSet))
	for amount := range amountsSet {
		amountsList = append(amountsList, amount)
	}

	// 对列表进行排序
	sort.Ints(amountsList)

	// 返回第 k 小的金额
	return int64(amountsList[k-1])
}
